# flask_login 注册
from flask_login import LoginManager

login_manager = LoginManager()


def init_login(app) -> None:
    login_manager.init_app(app)
    login_manager.login_view = 'auth.login'
    login_manager.login_message = '请先进行登录！'
    login_manager.login_message_category = 'info'
    login_manager.session_protection = 'basic'

    @login_manager.user_loader
    def load_user(user_id):
        from web.models.sql_data import User
        user = User.query.get(int(user_id))
        return user
